import { ChatType, MessageType } from "./chat.ts";

export enum CallContentStatus {
  Cancel = "cancel",
  Call = "call",
  Offer = "offer",
  Answer = "answer",
  SendCandidate = "sendCandidate",
  ReceiverCandidate = "receiveCandidate",
  Join = "join",
  End = "end",
}

export enum CallStatus {
  None = 0,
  wait = 1,
  agree = 2,
  reject = 3,
  cancel = 4,
  end = 5,
  record = 6,
}

export enum ToggleLocalStreamType {
  Video = "video",
  Audio = "audio",
}

interface IceServer {
  urls: string[];
}

interface ICallCandidates {
  id: number; //通话候选者
  name: string;
  avatar: string;
}

interface IOpenParams {
  sessionId: string; // 这里为了通话结束后发送通话信息
  chatType: ChatType; // 这里区分是私聊还是群聊
  messageType: MessageType; // 这里区分是语音还是视频
}

// 打开通知页面参数
interface IOpenNotifyParams extends IOpenParams {
  id: number; //通话候选者
  name: string;
  avatar: string;
  initiatorId: number; //通话发起者
}

// 打开语音或者视频页面参数
interface IOpenCallParams extends IOpenParams {
  isCall: boolean;
  initiatorId: number; //通话发起者
  callCandidateLists: ICallCandidates[];
}

interface RTCConfiguration {
  iceServers: IceServer[];
}

interface IMessageContent {
  offer?: RTCSessionDescriptionInit;
  answer?: RTCSessionDescriptionInit;
  candidate?: RTCIceCandidateInit;
}

interface ICallMessageType {
  type: CallContentStatus;
  content: RTCSessionDescriptionInit | RTCIceCandidateInit;
}
interface IButtonListItem {
  bg: string;
  handel: Function;
  icon: string;
  fontColor: string;
  fontSize: string;
}

interface IHandelCallMessageParams {
  CreateOffer: (CreateOfferCallBack: Function, SendCandidateCallback: Function) => void;
  CreateAnswer: (
    RTCSessionDescriptionInfo: RTCSessionDescriptionInit,
    CreateAnserCallback: Function,
    SendCandidateCallback: Function,
  ) => void;
  AddAnswer: (RTCSessionDescriptionInfo: RTCSessionDescriptionInit) => void;
  HandelAgreeCandidate: (RTCSessionDescriptionInfo: RTCIceCandidateInit) => void;
}

interface IEndCallParams {
  callStatus: CallStatus;
  content: string;
}
interface ISendRecordParams {
  status: CallStatus;
  data: string;
}

export type {
  ICallMessageType,
  IMessageContent,
  RTCConfiguration,
  IButtonListItem,
  IHandelCallMessageParams,
  IOpenNotifyParams,
  IOpenCallParams,
  ICallCandidates,
  IEndCallParams,
  ISendRecordParams,
};
